package com.zhongyouyun.admin.service.imp;

import com.zhongyouyun.admin.mapper.FileMapper;
import com.zhongyouyun.admin.model.FileModel;
import com.zhongyouyun.admin.service.FileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhongyouyun.other.file.Bean.FileBeanWork;
import com.zhongyouyun.other.file.FileImp;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author: shenyi
 * @Date: 2022-04-29
 * @Description: 服务实现类
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class FileServiceImpl extends ServiceImpl<FileMapper, FileModel> implements FileService {
    /*
     * @Author: shenyi
     * @Date: 2021-09-08
     * @Description: 分页查询
     * @param page 分页数据  lambdaQueryWrapper where 条件 和排序
     */
    @Override
    public IPage<FileModel> selectPage(Page<FileModel> page, QueryWrapper<FileModel> queryWrapper) {
        return this.baseMapper.selectPage(page, queryWrapper);
    }


    /*
     * @Author: shenyi
     * @Date: 2021-09-08
     * @Description: 查询全部
     * @param   lambdaQueryWrapper where 条件 和排序
     */
    @Override
    public List<FileModel> selectList(QueryWrapper<FileModel> queryWrapper) {
        return this.baseMapper.selectList(queryWrapper);
    }

    /*
     * @Author: shenyi
     * @Date: 2021-09-08
     * @Description: 查询ID
     */
    @Override
    public void ImpdownloadFile(FileModel fileModel, HttpServletRequest request, HttpServletResponse response) {
        fileModel = this.baseMapper.selectById(fileModel.getId());
        FileImp.ImpdownloadFile(fileModel, request, response);

    }

    @Override
    public FileBeanWork delFile(int id) {
        FileModel fileModel = this.baseMapper.selectById(id);
        return FileImp.delFile(fileModel);
    }
}
